package recursividad;
/* debemos sumar los datos en un vector pero usando recursividad (esde n=5 posiciones).
 * suma=suma(vector[4])
 * 	suma(vector[4])=vector[4]+suma(vector[3])
 * 	suma(vector[3])=vector[3]+suma(vector[2])
 * 	suma(vector[2])=vector[2]+suma(vector[1])
 * 	suma(vector[1])=vector[1]+suma(vector[0])
 * 	suma(vector[0])=vector[0]
 */
import javax.swing.JFrame;

public class Recur {

public Recur(){
	int n=5;
	int vector[]=new int[n];
	for (int i=0;i<n;i++){
		vector[i]=i+1;
		System.out.println(vector[i]);
	}
	int suma=0;
	suma=suma(vector,n-1,suma);
	System.out.println("suma:------");
	System.out.println(suma);
}

private int suma(int[] vector, int n, int suma) {
	if(n==0)
		suma=vector[0];	
	else
		suma=vector[n]+suma(vector,n-1,suma);		
		
	
	return suma;
}
}
